package com.woniu.adapter;

import com.woniu.outlet.mysql.GoldFundSellDao;
import com.woniu.outlet.mysql.po.GoldFundSellMySQL;
import com.woniu.service.bean.GoldFundSell;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
public class GoldFundSellAdapter {

    @Autowired
    private GoldFundSellDao goldFundSellDao;

    /**
     * 添加基金黄金的卖出数据到数据库
     * @param goldFundSell
     */
    public void AddGoldFundSell(GoldFundSell goldFundSell){
        GoldFundSellMySQL goldFundSellMySQL = new GoldFundSellMySQL();
        BeanUtils.copyProperties(goldFundSell,goldFundSellMySQL);
        goldFundSellDao.insertSelective(goldFundSellMySQL);
    }

    /**
     * 去重查询sid的方法
     */
    public Set<Integer> getSIds(){
        Set<Integer> s=new HashSet<>();
        List<GoldFundSellMySQL> goldFundSellMySQLS = goldFundSellDao.selectByExample(null);
        for (GoldFundSellMySQL m : goldFundSellMySQLS) {
            s.add(m.getSId());
        }
        return s;
    }

    /**
     * 根据sid查询对应的订单信息
     */
    public List<GoldFundSell> getGoldFundSellBySId(Integer sId){
        List<GoldFundSellMySQL> goldFundSellMySQLList = goldFundSellDao.selectBySId(sId);
        List<GoldFundSell> goldFundSellList = new ArrayList<GoldFundSell>();
        for (GoldFundSellMySQL goldFundSellMySQL:goldFundSellMySQLList) {
            GoldFundSell goldFundSell = new GoldFundSell();
            BeanUtils.copyProperties(goldFundSellMySQL,goldFundSell);
            goldFundSellList.add(goldFundSell);
        }
        return goldFundSellList;
    }

    /**
     * 根据sid删除订单信息（卖出撤销）
     */
    public void deleteById(Integer SId){
        goldFundSellDao.deleteByOrderSId(SId);
    }
}
